local sk__mozhi = fk.CreateSkill {

  name = "sk__mozhi",

  tags = {},

}



sk__mozhi:addEffect(fk.TurnEnd, {
  name = "sk__mozhi",
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__mozhi.name) then
      local room = player.room
      local name = ""
      local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      if not turn_event then return end
      room.logic:getEventsByRule(GameEvent.UseCard, 1, function(e)
        local use = e.data
        if use.from == target then
          name = use.card.name
          return true
        end
      end, turn_event.id)
      if name ~= "" then
        room:setPlayerMark(player, "sk__mozhi-turn", name)
        local card = Fk:cloneCard(name)
        return (card.type == Card.TypeBasic or card:isCommonTrick()) and player:canUse(card) and
        not player:prohibitUse(card)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local success, dat = player.room:askForUseActiveSkill(player, "sk__mozhi_viewas",
      "#sk__mozhi-invoke:::" .. player:getMark("sk__mozhi-turn"), true)
    if success then
      event:setCostData(self, dat)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local card = Fk:cloneCard(player:getMark("sk__mozhi-turn"))
    card:addSubcards(event:getCostData(self).cards)
    card.skillName = "sk__mozhi"
    player.room:useCard {
      from = player,
      tos = table.map(event:getCostData(self).targets, Util.Id2PlayerMapper),
      card = card,
      extraUse = true,
    }
  end,
})

return sk__mozhi
